package VIEW.OLD;

import CONTROLLERS.ReturnsController;
import UTIL.InputValidator;
import datechooser.beans.DateChooserCombo;
import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Belthazod
 */
public class Returns extends javax.swing.JPanel {
    private static ReturnsController returnsController;
    /**
     * Creates new form Returns
     */
    public Returns() {
        initComponents();
        //returnsController = new ReturnsController(e, receiptNumberInput, salesDateLabel, d, receiptNumberLabel, h, changeSerialNumberDialog, i, newSerialNumberInput, returnsTable, inputQuantityDialog, inputQuantityTextField, hideThis1, hideThis2, b, c, f, g,h, k);
        InputValidator.enabler(returnsTable, jButton3);
    }
//        private void enabler(){
//        b.setVisible(true);
//        c.setVisible(true);
//        d.setVisible(true);
//        e.setVisible(true);
//        f.setVisible(true);
//        g.setVisible(true);
//        h.setVisible(true);
//        i.setVisible(true);
//        k.setVisible(true);
//        }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        changeSerialNumberDialog = new javax.swing.JDialog();
        label1 = new java.awt.Label();
        newSerialNumberInput = new javax.swing.JTextField();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        inputQuantityDialog = new javax.swing.JDialog();
        jLabel8 = new javax.swing.JLabel();
        inputQuantityTextField = new javax.swing.JTextField();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        a = new javax.swing.JLabel();
        receiptNumberInput = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        hideThis2 = new javax.swing.JScrollPane();
        e = new javax.swing.JTable();
        b = new javax.swing.JLabel();
        receiptNumberLabel = new javax.swing.JLabel();
        c = new javax.swing.JLabel();
        h = new datechooser.beans.DateChooserCombo();
        jLabel6 = new javax.swing.JLabel();
        f = new javax.swing.JLabel();
        salesDateLabel = new javax.swing.JLabel();
        d = new javax.swing.JLabel();
        k = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        returnsTable = new javax.swing.JTable();
        g = new javax.swing.JLabel();
        hideThis1 = new javax.swing.JScrollPane();
        i = new javax.swing.JTextArea();
        jButton3 = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        warranty1 = new VIEW.Warranty();

        changeSerialNumberDialog.setTitle("New Serial Number Input");
        changeSerialNumberDialog.setBounds(new java.awt.Rectangle(165, 155, 420, 250));

        label1.setText("Enter Serial Number:");

        newSerialNumberInput.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                newSerialNumberInputKeyPressed(evt);
            }
        });

        jButton4.setText("OK");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("Cancel");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout changeSerialNumberDialogLayout = new javax.swing.GroupLayout(changeSerialNumberDialog.getContentPane());
        changeSerialNumberDialog.getContentPane().setLayout(changeSerialNumberDialogLayout);
        changeSerialNumberDialogLayout.setHorizontalGroup(
            changeSerialNumberDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(changeSerialNumberDialogLayout.createSequentialGroup()
                .addGroup(changeSerialNumberDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(changeSerialNumberDialogLayout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton5))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, changeSerialNumberDialogLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(changeSerialNumberDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(newSerialNumberInput, javax.swing.GroupLayout.PREFERRED_SIZE, 370, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(13, Short.MAX_VALUE))
        );
        changeSerialNumberDialogLayout.setVerticalGroup(
            changeSerialNumberDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(changeSerialNumberDialogLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(newSerialNumberInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(changeSerialNumberDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton5)
                    .addComponent(jButton4))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        inputQuantityDialog.setBounds(new java.awt.Rectangle(165, 155, 420, 250));

        jLabel8.setText("Enter Quantity:");

        jButton6.setText("OK");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton7.setText("Cancel");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout inputQuantityDialogLayout = new javax.swing.GroupLayout(inputQuantityDialog.getContentPane());
        inputQuantityDialog.getContentPane().setLayout(inputQuantityDialogLayout);
        inputQuantityDialogLayout.setHorizontalGroup(
            inputQuantityDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(inputQuantityDialogLayout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(inputQuantityDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(inputQuantityDialogLayout.createSequentialGroup()
                        .addComponent(jButton6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton7))
                    .addGroup(inputQuantityDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel8)
                        .addComponent(inputQuantityTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 349, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(26, Short.MAX_VALUE))
        );
        inputQuantityDialogLayout.setVerticalGroup(
            inputQuantityDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(inputQuantityDialogLayout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(inputQuantityTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(34, 34, 34)
                .addGroup(inputQuantityDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton6)
                    .addComponent(jButton7))
                .addContainerGap(43, Short.MAX_VALUE))
        );

        setBackground(new java.awt.Color(204, 204, 204));
        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Returns");
        add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 11, 1090, 19));

        jTabbedPane1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jPanel2.setBackground(new java.awt.Color(204, 204, 204));
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        a.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        a.setText("Receipt Number:");
        jPanel2.add(a, new org.netbeans.lib.awtextra.AbsoluteConstraints(33, 72, -1, -1));

        receiptNumberInput.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        receiptNumberInput.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                receiptNumberInputKeyPressed(evt);
            }
        });
        jPanel2.add(receiptNumberInput, new org.netbeans.lib.awtextra.AbsoluteConstraints(156, 69, 153, -1));

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton1.setText("Search");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(319, 70, -1, -1));

        e.setAutoCreateRowSorter(true);
        e.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        e.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "product_id", "Product Name", "Quantity"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        e.setRowHeight(20);
        hideThis2.setViewportView(e);
        if (e.getColumnModel().getColumnCount() > 0) {
            e.getColumnModel().getColumn(0).setResizable(false);
        }

        jPanel2.add(hideThis2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 201, 1030, 131));

        b.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        b.setText("Receipt Number:");
        jPanel2.add(b, new org.netbeans.lib.awtextra.AbsoluteConstraints(33, 106, -1, -1));

        receiptNumberLabel.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        jPanel2.add(receiptNumberLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 110, 229, 14));

        c.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        c.setText("Sales Date:");
        jPanel2.add(c, new org.netbeans.lib.awtextra.AbsoluteConstraints(33, 134, -1, -1));
        jPanel2.add(h, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 70, 188, 25));

        jLabel6.setText("  ");
        jPanel2.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(397, 112, -1, -1));

        f.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        f.setText("Date Returned:");
        jPanel2.add(f, new org.netbeans.lib.awtextra.AbsoluteConstraints(560, 70, -1, 25));

        salesDateLabel.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        jPanel2.add(salesDateLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 130, 229, 30));

        d.setText("jLabel9");
        jPanel2.add(d, new org.netbeans.lib.awtextra.AbsoluteConstraints(33, 165, -1, -1));
        d.setVisible(false);

        k.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        k.setText("Accept Product and Replace");
        k.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kActionPerformed(evt);
            }
        });
        jPanel2.add(k, new org.netbeans.lib.awtextra.AbsoluteConstraints(810, 340, 229, -1));

        returnsTable.setAutoCreateRowSorter(true);
        returnsTable.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        returnsTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "Product Id", "Date returned", "Receipt Number", "Product Name", "Quantity", "Remarks", "Old Product status"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        returnsTable.setRowHeight(20);
        jScrollPane2.setViewportView(returnsTable);
        if (returnsTable.getColumnModel().getColumnCount() > 0) {
            returnsTable.getColumnModel().getColumn(0).setResizable(false);
            returnsTable.getColumnModel().getColumn(2).setResizable(false);
            returnsTable.getColumnModel().getColumn(4).setMaxWidth(70);
        }

        jPanel2.add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 395, 1030, 135));

        g.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        g.setText("Remarks:");
        jPanel2.add(g, new org.netbeans.lib.awtextra.AbsoluteConstraints(560, 120, -1, -1));

        i.setColumns(20);
        i.setRows(5);
        hideThis1.setViewportView(i);

        jPanel2.add(hideThis1, new org.netbeans.lib.awtextra.AbsoluteConstraints(636, 115, 400, 80));

        jButton3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton3.setText("Return Old Product To Supplier");
        jButton3.setEnabled(false);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(820, 540, -1, -1));

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        jLabel10.setText("Returned Products");
        jPanel2.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 369, -1, -1));

        jLabel11.setBackground(new java.awt.Color(204, 204, 204));
        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel11.setText("Without Warranty");
        jPanel2.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 11, 1050, -1));

        jTabbedPane1.addTab("Without Warranty", jPanel2);
        jTabbedPane1.addTab("Under Warranty", warranty1);

        add(jTabbedPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 36, 1060, 598));
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        //returnsController.searchReceiptNumber();
//        enabler();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void kActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_kActionPerformed
        
        //returnsController.checkIfItemHasSerialNumber();
    }//GEN-LAST:event_kActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        if(!newSerialNumberInput.getText().trim().equals("")){
            //returnsController.acceptItem();
        }else{
            JOptionPane.showMessageDialog(null, "The new serial number cannot be empty. Please enter the new serial number for replacement.","New Serial Number is empty", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        changeSerialNumberDialog.dispose();
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        //returnsController.acceptItem();
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        inputQuantityDialog.setVisible(false);
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        //returnsController.returnToSupplier();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void receiptNumberInputKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_receiptNumberInputKeyPressed
        if (evt.getKeyCode()== KeyEvent.VK_ENTER)
	{
            jButton1.doClick();
	}
    }//GEN-LAST:event_receiptNumberInputKeyPressed

    private void newSerialNumberInputKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_newSerialNumberInputKeyPressed
       if (evt.getKeyCode()== KeyEvent.VK_ENTER)
	{
            jButton4.doClick();
	}
    }//GEN-LAST:event_newSerialNumberInputKeyPressed
    
    public static void updateReturnsHistoryTable(){
        //returnsController.updateReturnsTable();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel a;
    private javax.swing.JLabel b;
    private javax.swing.JLabel c;
    private static javax.swing.JDialog changeSerialNumberDialog;
    private javax.swing.JLabel d;
    private javax.swing.JTable e;
    private javax.swing.JLabel f;
    private javax.swing.JLabel g;
    private datechooser.beans.DateChooserCombo h;
    private javax.swing.JScrollPane hideThis1;
    private javax.swing.JScrollPane hideThis2;
    private javax.swing.JTextArea i;
    private static javax.swing.JDialog inputQuantityDialog;
    private javax.swing.JTextField inputQuantityTextField;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JButton k;
    private java.awt.Label label1;
    private javax.swing.JTextField newSerialNumberInput;
    private javax.swing.JTextField receiptNumberInput;
    private javax.swing.JLabel receiptNumberLabel;
    private javax.swing.JTable returnsTable;
    private javax.swing.JLabel salesDateLabel;
    private VIEW.Warranty warranty1;
    // End of variables declaration//GEN-END:variables
}
